package com.selune.online.ordering.system.project.tenant.controller;


import com.selune.online.ordering.system.project.api.base.response.Response;
import com.selune.online.ordering.system.project.api.pojo.category.dto.GoodsCategoryDTO;
import com.selune.online.ordering.system.project.api.pojo.category.vo.GoodsCategoryVO;
import com.selune.online.ordering.system.project.api.service.tenant.ITenantCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品类目控制器
 *
 * @author Selune
 * @date 2020-02-20
 */

@RestController
@RequestMapping("/api/v1/ordering/tenant/category")
@Slf4j
@Api(value = "商品类目信息接口")
public class TenantCategoryController {

	@Autowired
	private ITenantCategoryService iTenantCategoryService;
	
	@ApiOperation(value = "添加商品类目", notes = "添加商品类目")
	@ApiImplicitParam(name = "goodsCategoryDTO", value = "保存商品类目DTO", required = true, dataType = "GoodsCategoryDTO", paramType = "body")
	@PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> saveCategory(@RequestBody GoodsCategoryDTO goodsCategoryDTO) {
		
		return iTenantCategoryService.saveCategory(goodsCategoryDTO);
	}
	
	@ApiOperation(value = "修改商品类目", notes = "修改商品类目")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "categoryId", value = "商品类目id", required = true, dataType = "Long", paramType = "query"),
			@ApiImplicitParam(name = "goodsCategoryDTO", value = "商品类目DTO", required = true, dataType = "GoodsCategoryDTO", paramType = "body")
	})
	@PutMapping(value = "/update/{categoryId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> updateCategory(@PathVariable(value = "categoryId") Long categoryId,
	                                        @RequestBody GoodsCategoryDTO goodsCategoryDTO) {
		
		return iTenantCategoryService.updateCategory(categoryId, goodsCategoryDTO);
	}
	
	@ApiOperation(value = "查询商品类目", notes = "查询商品类目")
	@GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<List<GoodsCategoryVO>> listCategory() {
		
		return iTenantCategoryService.listCategory();
	}
	
	@ApiOperation(value = "根据id查找商品类目", notes = "根据id查找商品类目")
	@ApiImplicitParam(name = "categoryId", value = "商品类目id", required = true, dataType = "Long", paramType = "query")
	@GetMapping(value = "/info/{categoryId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<GoodsCategoryVO> findCategoryById(@PathVariable("categoryId") Long categoryId) {
		
		return iTenantCategoryService.findCategoryById(categoryId);
	}
	
	@ApiOperation(value = "删除商品类目", notes = "删除商品类目")
	@ApiImplicitParam(name = "categoryId", value = "商品类目id", required = true, dataType = "Long", paramType = "query")
	@DeleteMapping(value = "/delete/{categoryId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> deleteCategory(@PathVariable(value = "categoryId") Long categoryId) {
		
		return iTenantCategoryService.deleteCategory(categoryId);
	}

}
